package com.suke.czx.modules.tb.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.suke.czx.modules.tb.mapper.TbLikesMapper;
import com.suke.czx.modules.tb.mapper.TbUserFavoriteMapper;
import com.suke.czx.modules.tb.vo.ProductQueryVO;
import com.suke.czx.modules.tb.vo.ProductVO;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import com.suke.czx.modules.tb.mapper.TbProductMapper;
import com.suke.czx.modules.tb.entity.TbProduct;
import com.suke.czx.modules.tb.service.TbProductService;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


/**
 * 商品表
 *
 * @author developer
 * @email developer@163.com
 * @date 2025-05-14 21:06:11
 */
@Service
public class TbProductServiceImpl extends ServiceImpl<TbProductMapper, TbProduct> implements TbProductService {

    @Resource
    private TbUserFavoriteMapper tbUserFavoriteMapper;

    @Resource
    private TbLikesMapper tbLikesMapper;


    @Override
    public List<ProductVO> recommendList(ProductQueryVO productQueryVO) {
        String userId = productQueryVO.getUserId();
        Integer categoryId = productQueryVO.getCategoryId();
        // 收藏
        if (-1 == categoryId) {
            return baseMapper.recommendListSc(userId,productQueryVO.getName());
        } else if (0 == categoryId) {
            // 推荐
            return baseMapper.recommendList(productQueryVO.getName());
        }
        // 根据分类
        return baseMapper.recommendListByCategoryId(categoryId, productQueryVO.getName());
    }

    @Override
    public ProductVO getDetailById(Long productId) {
        ProductVO productVO = baseMapper.getDetailById(productId);
//        productVO.setLikeCount(tbLikesMapper.likeCountByProductId(productId));
//        productVO.setFavoriteCount(tbUserFavoriteMapper.favoriteCountByProductId(productId));
        return productVO;
    }
}
